import React from 'react'
import { useRef } from 'react'
import axios from 'axios';
export default function Search(props) {
  //关键词
  const keyWord = useRef(null);
  var search = ()=>{
    const key = keyWord.current.value;
    axios.get(`https://api.github.com/search/users?q=${key}`).then(
      response => {
        props.saveUsers(response.data.items)
      },
      error => {console.log('fail', error)}
    )
  }
  return (
    <div>
       <section className="jumbotron">
        <h3 className="jumbotron-heading">搜索github用户</h3>
        <div>
          <input ref={keyWord} type="text" placeholder="输入关键词搜索"/>&nbsp;
          <button onClick={search}>搜索</button>
        </div>
      </section>
    </div>
  )
}
